package com.cd.common.domain;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.cd.common.exception.LqqException;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.Map;
import java.util.Set;

/**
 * @author admin
 * @description 角色信息表 ||  ||
 * @date 2024-03-25
 */
@Entity
@Data
@Table(name = "sys_role")
@NoArgsConstructor
public class SysRole implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    //@Comment("角色ID")
    @Column(name = "role_id", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long roleId;

    //@Comment("角色名称")
    @Column(name = "role_name", nullable = false)
    private String roleName;

    //@Comment("角色权限字符串")
    @Column(name = "role_key", nullable = false)
    private String roleKey;

    //@Comment("显示顺序")
    @Column(name = "role_sort", nullable = false)
    private Long roleSort;

    //@Comment("数据范围（1：全部数据权限 2：自定数据权限 3：本部门数据权限 || 数据范围（1：全部数据权限 2：自定数据权限 3：本部门数据权限 4：本部门及以下数据权限）")
    @Column(name = "data_scope")
    private String dataScope;

    //@Comment("菜单树选择项是否关联显示")
    //    /** 菜单树选择项是否关联显示（ 0：父子不互相关联显示 1：父子互相关联显示） */
    @Column(name = "menu_check_strictly")
    private boolean menuCheckStrictly;

    /**
     * 部门树选择项是否关联显示（0：父子不互相关联显示 1：父子互相关联显示 ）
     */
    //@Comment("部门树选择项是否关联显示")
    @Column(name = "dept_check_strictly")
    private boolean deptCheckStrictly;

    //@Comment("角色状态（0正常 1停用）")
    @Column(name = "status", nullable = false)
    private String status;

    //@Comment("删除标志（0代表存在 2代表删除）")
    @Column(name = "del_flag",columnDefinition = "VARCHAR(20) DEFAULT '0'")
    private String delFlag;

    //@Comment("创建者")
    @Column(name = "create_by")
    private String createBy;

    //@Comment("创建时间")
    @Column(name = "create_time")
    private Date createTime;

    //@Comment("更新者")
    @Column(name = "update_by")
    private String updateBy;

    //@Comment("更新时间")
    @Column(name = "update_time")
    private Date updateTime;

    //@Comment("备注")
    @Column(name = "remark")
    private String remark;

    /**
     * 请求参数
     */
    @Transient
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private Map<String, Object> params;

    @Transient
    /** 菜单组 */
    private Long[] menuIds;
    @Transient
    /** 部门组（数据权限） */
    private Long[] deptIds;
    @Transient
    /** 角色菜单权限 */
    private Set<String> permissions;

    public boolean isAdmin() {
        return isAdmin(this.roleId);
    }

    public static boolean isAdmin(Long roleId) {
        return roleId != null && 1L == roleId;
    }

    public SysRole(Long roleId) {
        this.roleId = roleId;
    }


    public boolean isMenuCheckStrictly() {
//        if (menuCheckStrictly.equals(1L)){
//            return true;
//        }
//        if (menuCheckStrictly.equals(0L)){
//            return false;
//        }
        return menuCheckStrictly;
    }
}

